{layout name="layout" /}

<div class="Hui-article">
    <div class="pd-20">
        <div class="text-c" style="margin-right: 10%;">
            <form action="" method="GET" id='search'>
                <a href="{:url('index')}" class="btn btn-danger">清除条件</a>
                <!-- 日期范围：
                    <input type="date" id="logmin" class="input-text Wdate" style="width:150px;">
                    -
                    <input type="date" id="logmax" class="input-text Wdate" style="width:150px;"> -->
                <span>留言类型:</span>
                <select id="status" name="status">
                    <option value="0">--全部--</option>
                    <option value="1">--网站留言--</option>
                    <option value="2">--文章评论--</option>
                </select>
                <span style="margin-left: 20px;">留言状态:</span>
                <select id="status" name="status">
                    <option value="0">--全部--</option>
                    <option value="1">--已回复--</option>
                    <option value="2">--未回复--</option>
                </select>
                <input type="text" name="search" id="search" value="{notempty name='search'}{$search}{/notempty}" placeholder="留言内容" style="width:250px"
                    class="input-text">
                <button name="" id="" class="btn btn-success" type="submit">
                    <i class="Hui-iconfont">&#xe665;</i> 搜内容</button>
            </form>
        </div>
        <div class="cl pd-5 bg-1 bk-gray mt-20">
            <span class="l">
                <a href="javascript:;" onclick="del_all('article')" class="btn btn-danger radius">
                    <i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a>
            </span>
            <span class="r">
                <a href="javascript:;" class="btn btn-success radius">
                    <i class="Hui-iconfont">&#xe6e2;</i>批量标记已读</a>
                <a href="javascript:;" class="btn btn-primary radius" style="margin-left: 20px;">
                    <i class="Hui-iconfont">&#xe6e2;</i>批量标记未读</a>
            </span>
        </div>
        <div class="mt-20">
            <table class="table table-border table-bordered table-bg table-hover table-sort">
                <thead>
                    <tr class="text-c">
                        <th width="20px">
                            <input type="checkbox" value="" name="allcheck">
                        </th>
                        <th width="40px">ID</th>
                        <th width="100px">姓名</th>
                        <th width="120px">邮箱</th>
                        <th width="100px">手机号</th>
                        <th>内容</th>
                        <th width="80px">留言类型</th>
                        <th width="40px">PID(楼层id)</th>
                        <th width="40px">RID(回复id)</th>
                        <th width="120px">发布日期</th>
                        <th width="80px">状态</th>
                        <th width="160px">操作</th>
                    </tr>
                </thead>
                <tbody>
                    {foreach $data as $val}
                    <tr class="text-c va-m" style="height:20px;">
                        <td>
                            <input type="checkbox" value="{$val.id}" name="checkbox[]">
                        </td>
                        <td>{$val.id}</td>
                        <td>{$val.name}</td>
                        <td>{$val.email}</td>
                        <td>{$val.phone}</td>
                        <td class="text-l">{$val.content}</td>
                        <td>{eq name="val.aid" value="0"}网站留言{else/}文章ID:{$val.aid}{/eq}</td>
                        <td>{$val.pid}</td>
                        <td>{$val.rid}</td>
                        <td>{$val.time|date="Y-m-d H:i:s", ###}</td>
                        <td class="td-status">{$val.status|default="未处理"}</td>
                        <td class="td-manage">
                            {neq name="val.type" value="3"}
                            <a href="javascript:void(0);" title="标记已读" style="text-decoration:none" class="ml-10">
                                <i class="Hui-iconfont">&#xe70b;</i>
                            </a>
                            <a href="javascript:void(0);" title="标记未读" style="text-decoration:none" class="ml-10">
                                <i class="Hui-iconfont">&#xe63b;</i>
                            </a>
                            <a href="javascript:void(0);" title="回复" style="text-decoration:none" class="ml-10">
                                <i class="Hui-iconfont">&#xe6df;</i>
                            </a>
                            {else/}
                            <button class="btn btn-default radius">我的回复</button>
                            {/neq}
                            <a href="javascript:void(0);" title="删除" style="text-decoration:none" class="ml-10" onClick="del(this,'{$val.id}')">
                                <i class="Hui-iconfont">&#xe6e2;</i>
                            </a>
                        </td>
                    </tr>
                    {/foreach}
                </tbody>
            </table>
        </div>
        <div class="cl pd-5 bg-1 bk-gray mt-20 ">
            <span class="l">共
                <strong>{$counts}</strong> 篇, {$pages} 页 </span>
            <span class="r">
                {$data->render()}
            </span>
        </div>
    </div>
</div>

<!-- 请在下方写此页面业务相关的脚本 -->
<script type="text/javascript">
    //条件删选: 置顶 /上线 /审核
    $(".btn").click(function () {
        var input = $(this).children('label').children('input');
        if (input.attr('disabled') == null) {
            $(input).attr('disabled', true);
            $(this).removeClass();
            $(this).addClass('btn btn-default radius');
        } else {
            $(input).removeAttr('disabled');
            $(this).removeClass();
            $(this).addClass('btn btn-success radius');
        }
    })

    /* 文章-置顶 */
    function top_stat(action, obj, id) {
        var value = 2;
        var title = '置顶';
        var status = '非置顶';
        var color = 'default';
        if (action == "up") {
            var value = 1;
            var title = '取消置顶';
            var status = '置&nbsp;&nbsp;&nbsp;顶';
            var color = 'success';
            action = 'down';
        } else {
            action = 'up';
        }

        var text = "<a href=\"javascript:void(0);\" title='" + title + "' onClick=\"top_stat('" + action + "',this," +
            id +
            ")\">";
        text += '<span class="label label-' + color + ' radius" style="margin-left: 10%">' + status + '</span>';
        text += '</a>';

        $.post('{:url("top")}', {
            'id': id,
            'value': value
        }, function (data) {
            if (data.code == 2) {
                $(obj).after(text);
                $(obj).remove();
                layer.msg(data.msg, {
                    icon: 6,
                    time: 1000
                });
            } else {
                layer.msg(data.msg, {
                    icon: 5,
                    time: 1000
                });
            }
        }, 'json');
    }
    /* 批量置顶 or 取消 */
    function duty_all_top_up() {
        var checkbox = $('.text-c input[name="checkbox[]"]');

        if (checkboxtest(checkbox) == false) {
            return false;
        }

        checkbox.each(function (x) {
            if (this.checked) {
                var obj = $(this).parents('tr').find('.td-status').children('a.top');
                var id = $(this).val();
                top_stat('up', obj, id);
            }
        });
    }

    function duty_all_top_down() {
        var checkbox = $('.text-c input[name="checkbox[]"]');

        if (checkboxtest(checkbox) == false) {
            return false;
        }

        checkbox.each(function (x) {
            if (this.checked) {
                var obj = $(this).parents('tr').find('.td-status').children('a.top');
                var id = $(this).val();
                top_stat('down', obj, id);
            }
        });
    }


    /* 上线 or 下线 */
    function status(action, obj, id) {
        var value = 2;
        var title = '上线';
        var status = '下线';
        var color = 'default';
        if (action == 'up') {
            value = 1;
            action = 'down';
            title = '下线';
            status = '正常';
            color = 'success';
        } else {
            action = 'up';
        }

        var text = "<a href=\"javascript:void(0);\" title='" + title + "' onClick=\"status('" + action + "',this," + id +
            ")\">";
        text += '<span class="label label-' + color + ' radius" style="margin-left: 10%">' + status + '</span>';
        text += '</a>';

        $.post('status', {
            'id': id,
            'value': value
        }, function (data) {
            if (data.code == 2) {
                $(obj).after(text);
                $(obj).remove();
                layer.msg(data.msg, {
                    icon: 6,
                    time: 1000
                });
            } else {
                layer.msg(data.msg, {
                    icon: 5,
                    time: 1000
                });
            }
        }, 'json');
    }
    /* 批量置顶 or 取消 */
    function duty_all_status_up() {
        var checkbox = $('.text-c input[name="checkbox[]"]');

        if (checkboxtest(checkbox) == false) {
            return false;
        }
        checkbox.each(function (x) {
            if (this.checked) {
                var obj = $(this).parents('tr').find('.td-status').children('a.status');
                var id = $(this).val();
                status('up', obj, id);
            }
        });
    }

    function duty_all_status_down() {
        var checkbox = $('.text-c input[name="checkbox[]"]');

        if (checkboxtest(checkbox) == false) {
            return false;
        }
        checkbox.each(function (x) {
            if (this.checked) {
                var obj = $(this).parents('tr').find('.td-status').children('a.status');
                var id = $(this).val();
                status('down', obj, id);
            }
        });
    }


    /*文章-审核*/
    function duty(obj, id) {
        layer.confirm('审核文章？', {
                btn: ['通过', '不通过', '取消'],
                shade: false
            },
            function () {
                do_duty('pass', obj, id);
                // pass(obj, id);
            },
            function () {
                do_duty('reject', obj, id)
                // reject(obj, id);
            },
            function () {
                return false;
            }
        );
    }

    function do_duty(action, obj, id) {
        var post = 0;
        if (action == 'pass') {
            post = 1;
        } else {
            post = 2;
        }
        $.post('duty', {
            'id': id,
            'post': post
        }, function (data) {
            if (data.code == 2) {
                console.log('test');
                $(obj).parents("tr").find(".td-dutyadmin").html(data.dutyadmin);
                $(obj).parents("tr").find(".td-time").html(data.time);
                if (action == 'pass') {
                    $(obj).parents("tr").find(".td-duty").html(
                        '<a href="javascript:void(0);" title="撤销审核" onClick="dutyDown(this,' + id +
                        ')" ><span class="label label-success radius">已过审</span></a>');
                } else {
                    $(obj).parents("tr").find(".td-duty").html(
                        '<a href="javascript:void(0);" title="通过审核" onClick="dutyUp(this,' + id +
                        ')" ><span class="label label-danger radius">未通过</span></a>');
                }
                $(obj).remove();
                layer.msg(data.msg, {
                    icon: 6,
                    time: 1000
                });
            } else {
                layer.msg(data.msg, {
                    icon: 5,
                    time: 1000
                });
            }
        }, 'json');
    }

    function dutyUp(obj, id) {
        layer.confirm('确认通过审核？', function (index) {
            do_duty('pass', obj, id);
        });
    }

    function dutyDown(obj, id) {
        layer.confirm('确认撤销审核？', function (index) {
            do_duty('reject', obj, id)
        });
    }

    /*文章-批量审核通过 / 驳回 */
    function duty_all_pass() {
        layer.confirm('确认通过审核？', function (index) {
            var checkbox = $('.text-c input[name="checkbox[]"]');
            checkbox.each(function (x) {
                if (this.checked) {
                    var obj = $(this).parents('tr').find('.td-duty').children('a');
                    var id = $(this).val();
                    do_duty('pass', obj, id);
                }
            })
        });
    }

    function duty_all_reject() {
        layer.confirm('确认驳回审核？', function (index) {
            var checkbox = $('.text-c input[name="checkbox[]"]');
            checkbox.each(function (x) {
                if (this.checked) {
                    var obj = $(this).parents('tr').find('.td-duty').children('a');
                    var id = $(this).val();
                    do_duty('reject', obj, id);
                }
            })
        });
    }

    /* 检查多选是否为空 */
    function checkboxtest(boxes) {
        var ids = new Array();
        boxes.each(function (x) {
            if (this.checked)
                ids.push(this.value);
        })

        var length = ids.length;

        if (length != 0) {
            return true;
        }
        layer.msg('请选择要删除的选项', {
            icon: 5,
            time: 1000
        });

        return false;
    }

    /*点击展开子栏目*/
    $(function () {
        $(".category").click(function () {
            var cid = $(this).data('cid');
            var status = $(this).data('status');

            if (status == 1) {
                $(".level_" + cid).css('display', 'none');
                $(".top_" + cid).css('display', 'none');
                $(this).children('i').html('&#xe698');
                $(this).data('status', 0);
                $(".level_" + cid).children('label').children('a').data('status', 0);
                return false;
            }
            $(".level_" + cid).css('display', 'block');
            $(this).children('i').html('&#xe69a');
            $(this).data('status', 1);

            return false;
        })
    });

    /*展开所有栏目*/
    function load_all() {
        $('.son').toggle();
        $('.grandson').toggle();
    }
</script>
<!--/请在上方写此页面业务相关的脚本-->